<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>

<c:choose>
    <c:when test="${null != actionBean.resultMenuItem}">
        <div id="modifyMenuViewDiv">
	        <stripes:form id="menuItemModifyFrom" beanclass="com.feib.soeasy.action.Soez9003ActionBean" 
	            method="post">        
	            <table id="MenuItemTable">
	                <tr>
	                    <th>程式類別</th>
	                    <td>
	                        <select id="menuTypex" name="menuType">
	                            <option value="0" <c:if test="${empty actionBean.resultMenuItem.parentMenuItem }">selected="selected"</c:if> >程式群組</option>
	                            <option value="1" <c:if test="${!empty actionBean.resultMenuItem.parentMenuItem }">selected="selected"</c:if>>程式功能</option>
	                        </select>
	                    </td>
	                </tr>
	                <tr>
	                    <th>上層程式<span id="mustKeyInStar">**</span></th>
	                    <td>
	                        <stripes:select id="parentMenuIdx" name="resultMenuItem.parentMenuItem.menuItemPk" >
	                            <stripes:option value="">-- 請選擇 --</stripes:option>
	                            <stripes:options-collection collection="${actionBean.parentMenuItemOptions }" label="label" value="value"/>
	                        </stripes:select>	
	                        <font color="red">若程式類別為程式群組, 則不能輸入<br>若為程式功能, 則必選</font>                    
	                    </td>
	                </tr>
	                <tr>
	                    <th>程式代號<span id="mustKeyInStar">**</span></th>
	                    <td>
	                        <stripes:text id="menuIdx" name="resultMenuItem.menuId" size="30" maxlength="50" />
	                    </td>
	                </tr>                
	                <tr>
	                    <th>程式名稱</th>
	                    <td>
	                        <stripes:text id="actionNamex" name="resultMenuItem.actionName" size="30" maxlength="50" />
	                    </td>
	                </tr>
	                <tr>
	                    <th>程式PAGE</th>
	                    <td>
	                        <stripes:text id="actionPagex" name="resultMenuItem.actionPage" size="30" maxlength="50" />
	                    </td>
	                </tr>
	                <tr>
	                    <th>程式類別名稱</th>
	                    <td>
	                        <stripes:text id="actionBeanx" name="resultMenuItem.actionBean" size="30" maxlength="50" />
	                    </td>
	                </tr>
                    <tr>
                        <th>排序</th>
                        <td>
                            <stripes:text id="orderNox" name="resultMenuItem.orderNo" size="30" maxlength="50" />
                        </td>
                    </tr>	                
	                <tr>
	                    <th>是否有效</th>
	                    <td>
                            <select id="enabledx" name="resultMenuItem.enabled">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.enabled }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.enabled }">selected="selected"</c:if>>停用</option>
                            </select>   
	                    </td>
	                </tr>                   
                    <tr>
                        <th>學校可用</th>
                        <td>
                            <select id="schoolx" name="resultMenuItem.school">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.school }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.school }">selected="selected"</c:if>>停用</option>
                            </select>   
                        </td>
                    </tr>                  
                    <tr>
                        <th>一般收費可用</th>
                        <td>
                            <select id="committeex" name="resultMenuItem.committee">
                                <option value="True" <c:if test="${actionBean.resultMenuItem.committee }">selected="selected"</c:if> >啟用</option>
                                <option value="False" <c:if test="${!actionBean.resultMenuItem.committee }">selected="selected"</c:if>>停用</option>
                            </select>   
                        </td>
                    </tr>
	                <tr>
	                    <td colspan="2" class="queryFunction">
	                        <stripes:button id="doModifyBtn" name="doModifyBtn" value="確認" class="formBtn"/>
	                        <stripes:button id="doDeleteBtn" name="doDeleteBtn" value="刪除" class="formBtn"/>
							<input type="button" id="closEditMenuItemBtn" value="離開" class="formBtn"/>
	                    </td>
	                </tr>	                
	            </table>
	        </stripes:form>    
        </div>
        <div id="modifyMenuItemHiddenFormDiv" style="display: none; ">
		    <stripes:form id="modifyMenuItemHiddenFrom" beanclass="com.feib.soeasy.action.Soez9003ActionBean" 
		        method="post" onsubmit="javascript: return false;">         
		        <input type="hidden" id="hidden2.resultMenuItem.menuItemPk" name="resultMenuItem.menuItemPk" value="<c:out value='${actionBean.resultMenuItem.menuItemPk}'/>"/>
		        <input type="hidden" id="hidden2.menuType" name="resultMenuItem.menuType"/>  
		        <input type="hidden" id="hidden2.resultMenuItem.parentMenuItem.menuItemPk" name="resultMenuItem.parentMenuItem.menuItemPk"/>
		        <input type="hidden" id="hidden2.resultMenuItem.menuId" name="resultMenuItem.menuId"/>                    
		        <input type="hidden" id="hidden2.resultMenuItem.actionName" name="resultMenuItem.actionName"/>
		        <input type="hidden" id="hidden2.resultMenuItem.actionPage" name="resultMenuItem.actionPage"/>
		        <input type="hidden" id="hidden2.resultMenuItem.actionBean" name="resultMenuItem.actionBean"/>
		        <input type="hidden" id="hidden2.resultMenuItem.orderNo" name="resultMenuItem.orderNo"/>
		        <input type="hidden" id="hidden2.resultMenuItem.enabled" name="resultMenuItem.enabled"/>
                <input type="hidden" id="hidden5.resultMenuItem.school" name="resultMenuItem.school"/>
                <input type="hidden" id="hidden5.resultMenuItem.committee" name="resultMenuItem.committee"/>
		        <input type="hidden" id="method3" name="doMenuItemModifyAction"/>
		    </stripes:form>
		</div>
		<div id="modifyMenuItemMsgDiv" style="display: none; ">
		</div> 
        <div id="deleteMenuItemHiddenFormDiv" style="display: none; ">
            <stripes:form id="deleteMenuItemHiddenFrom" beanclass="com.feib.soeasy.action.Soez9003ActionBean" 
                method="post" onsubmit="javascript: return false;">         
                <input type="hidden" id="hidden4.resultMenuItem.menuItemPk" name="resultMenuItem.menuItemPk" value="<c:out value='${actionBean.resultMenuItem.menuItemPk}'/>"/>
                <input type="hidden" id="method5" name="doMenuItemDeleteAction"/>
            </stripes:form>
        </div>
		<div id="deleteMenuItemMsgDiv" style="display: none; ">
        </div> 
        <script type="text/javascript">
        <!--
	        $(document).ready(function() {
	            $("#doModifyBtn").click(function() {
	                var menuType = $('#menuTypex').val();
	                var parentMenuId = $('#parentMenuIdx').val();
	                var menuId = $('#menuIdx').val();
	                var actionName = $('#actionNamex').val();
	                var actionPage = $('#actionPagex').val();
	                var actionBean = $('#actionBeanx').val();
	                var orderNo = $('#orderNox').val();
	                var enabled = $('#enabledx').val();
                    var school = $('#schoolx').val();
                    var committee = $('#committeex').val();
	                
	                $('#hidden2\\.menuType').val(menuType);
	                $('#hidden2\\.resultMenuItem\\.parentMenuItem\\.menuItemPk').val(parentMenuId);
	                $('#hidden2\\.resultMenuItem\\.menuId').val(menuId);
	                $('#hidden2\\.resultMenuItem\\.actionName').val(actionName);
	                $('#hidden2\\.resultMenuItem\\.actionPage').val(actionPage);
	                $('#hidden2\\.resultMenuItem\\.actionBean').val(actionBean);
	                $('#hidden2\\.resultMenuItem\\.orderNo').val(orderNo);
	                $('#hidden2\\.resultMenuItem\\.enabled').val(enabled); 
                    $('#hidden5\\.resultMenuItem\\.school').val(school)
                    $('#hidden5\\.resultMenuItem\\.committee').val(committee);              
	                
	                var errorMessage = '';
	                
	                if (null == menuId || 0 == menuId.length){
	                	errorMessage = errorMessage + '程式代號是必要欄位<br />';
	    			}
	                if (null == actionName || 0 == actionName.length){
	                	errorMessage = errorMessage + '程式名稱是必要欄位<br />';
	    			}
	                if (menuType == '1' )
	                	if  (null == actionPage || 0 == actionPage.length)
							  errorMessage = errorMessage +'程式類別為程式功能, 則程式PAGE是必要欄位<br />';
	                
	                if (menuType == '1' ) 
	                    if  (null == actionBean || 0 == actionBean.length)
	                	errorMessage = errorMessage +'程式類別為程式功能, 則程式類別名稱 是必要欄位<br />';
	                
	                if (menuType == '0' && parentMenuId != '') 
	                	errorMessage = errorMessage +'程式類別為程式群組, 則不能選擇上層程式<br />';
                    if (menuType == '1' && parentMenuId == '') 
                        errorMessage = errorMessage +'程式類別為程式功能, 請選擇上層程式<br />';
                    
                    if (null != orderNo && 0 != orderNo.length){
                    	var checkNum = parseInt(orderNo, 10);
                    	if(isNaN(checkNum))
                    		errorMessage = errorMessage +'排序須為整數 <br />';
                    }
	                
                    if (0 != errorMessage.length){
        				$("#ajaxErrorMessageDiv").html(errorMessage);
        				$("#ajaxErrorMessageDiv" ).dialog({  
        					title:'請修正下列錯誤' 
        					,width: 300
        					, resizable: false
        					, modal: true
        					, buttons: {
        						Ok: function() {
        							$( this ).dialog( "close" );
        						}
        					}
        				});
        				
        				return false;
        			}	                
	                
	                waitingDialog({});
	                $.ajax({url : "<c:url value='/ajax/Soez9003.action'/>",
	                    async : false,
	                    type : 'POST',
	                    data : $("#modifyMenuItemHiddenFrom").serialize(),
	                    dataType : 'html',
	                    success : function(data, textStatus, XMLHttpRequest){
	                            $("#modifyMenuViewDiv").hide();
	                            $("#modifyMenuItemMsgDiv" ).html(data);
	                            $("#modifyMenuItemMsgDiv").show();
	                        },
	                    error : function(XMLHttpRequest, textStatus, errorThrown){
	                        $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
	                        $("#ajaxErrorMessageDiv" ).dialog( "destroy" );
	                        $("#ajaxErrorMessageDiv" ).dialog({  
	                            title:'系統錯誤' 
	                            ,width: 600
	                            , resizable: false
	                            , modal: true
	                            , buttons: {
	                                Ok: function() {
	                                    $( this ).dialog( "close" );
	                                }
	                            }
	                        });
	                        },
	                    complete: function(XMLHttpRequest, textStatus){
	                        closeWaitingDialog();
	                    }
	                });
	            });            
	        });        
        
        $(document).ready(function() {
            $("#doDeleteBtn").click(function() {
            	var answer = confirm('是否確定刪除 ?');
            	
            	if (!answer)
            		return ;
            	
                waitingDialog({});
                $.ajax({url : "<c:url value='/ajax/Soez9003.action'/>",
                    async : false,
                    type : 'POST',
                    data : $("#deleteMenuItemHiddenFrom").serialize(),
                    dataType : 'html',
                    success : function(data, textStatus, XMLHttpRequest){
                            $("#modifyMenuViewDiv").hide();
                            $("#deleteMenuItemMsgDiv" ).html(data);
                            $("#deleteMenuItemMsgDiv").show();
                        },
                    error : function(XMLHttpRequest, textStatus, errorThrown){
                        $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                        $("#ajaxErrorMessageDiv" ).dialog( "destroy" );
                        $("#ajaxErrorMessageDiv" ).dialog({  
                            title:'系統錯誤' 
                            ,width: 600
                            , resizable: false
                            , modal: true
                            , buttons: {
                                Ok: function() {
                                    $( this ).dialog( "close" );
                                }
                            }
                        });
                        },
                    complete: function(XMLHttpRequest, textStatus){
                        closeWaitingDialog();
                    }
                });
            });

    		
    		$("#closEditMenuItemBtn").click(function() {
    			$("#menuItemDiv").dialog("close");
    		});
    		
        });    
        //-->
        </script>        
    </c:when>
    <c:otherwise>
            查無資料
        <script type="text/javascript">
        <!--
        $(document).ready(function() {
            $( "#menuItemDiv" ).dialog({  title:'權限功能資料' ,width: 600, resizable: false, modal: true  });
        });
        //-->
        </script>
    </c:otherwise>
</c:choose>    